"""

Computational Economics
04: Conditionals
http://johnstachurski.net/lectures/conditionals.html

    Recently I received the following chain email:

    Don't tell me your age; your waiter may know!

       1. First of all, pick the number of times a week that you would like to
          go out to eat. (more than once but less than 10)
       2. Multiply this number by 2
       3. Add 5
       4. Multiply it by 50
       5. If you have already had your birthday this year add 1758...If you
          haven't, add 1757.
       6. Now subtract the four digit year that you were born.

    You should have a three digit number

    The first digit of this was your original number. (I.e., How many times you want to go out to restaurants in a week.) The next two numbers are YOUR AGE!

    Write a program which asks the user to answer these questions, does the calculations and prints our their age.

"""

# what we're trying to find
result = 0

# steps 1 - 4
prompt = 'First, pick the number of times a week that you would like go out to eat (2-9): '
answer_is_ok = False
while not answer_is_ok:
    num_eat_out = int(raw_input(prompt))
    if num_eat_out <= 1 or num_eat_out >= 10:
        print 'Number must be between 2 and 9. Please try again.'
    else:
        answer_is_ok = True
result += (num_eat_out * 2 + 5) * 50

# step 5
prompt = 'Have you had your birthday this year yet? (y/n) '
answer_is_ok = False
while not answer_is_ok:
    had_birthday = raw_input(prompt)
    answer_is_ok = True
    if had_birthday.upper().startswith('Y'):
        had_birthday = True
    elif had_birthday.upper().startswith('N'):
        had_birthday = False
    else:
        print 'Answer must be y or n. Please try again.'
        answer_is_ok = False

if had_birthday:
    result += 1758
else:
    result += 1757


# step 6
prompt = 'What year were you born? '
answer_is_ok = False
while not answer_is_ok:
    birthyear = raw_input(prompt)
    answer_is_ok = True
    if not birthyear.startswith('19') and not birthyear.startswith('20'):
        print 'You were born in the year%s!? Please try again.' % (birthyear)
        answer_is_ok = False
    if len(birthyear) != 4:
        print 'Answer must be a 4 digits (e.g. 1980). Please try again.'
        answer_is_ok = False
    else:
        birthyear = int(birthyear)
        answer_is_ok = True

result -= birthyear


# output
print 'result: %s' % (result)
print 'Your original number was: %s' % (str(result)[0])
print 'Your age is: %s' % (str(result)[1:])


print '%s: ok' % (__file__)
